home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / bgui / Examples / Source / MultiFont.c < prev    next >
C/C++ Source or Header  |  2000-05-09  |  5KB  |  194 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/MultiFont.c,v 41.11 2000/05/09 20:33:49 mlemos Exp $
  3.  *
  4.  * MultiFont.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995 Jaba Development.
  8.  * (C) Copyright 1995 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * $Log: MultiFont.c,v $
  12.  * Revision 41.11  2000/05/09 20:33:49  mlemos
  13.  * Bumped to revision 41.11
  14.  *
  15.  * Revision 1.2  2000/05/09 19:59:06  mlemos
  16.  * Merged with the branch Manuel_Lemos_fixes.
  17.  *
  18.  * Revision 1.1.2.1  1998/02/28 17:45:34  mlemos
  19.  * Ian sources
  20.  *
  21.  *
  22.  */
  23.  
  24. /*
  25. dcc MultiFont.c -mi -ms -mRR -proto -lbgui
  26. quit
  27. */
  28.  
  29. #include "DemoCode.h"
  30.  
  31. /*
  32.  *    Fonts used in the code.
  33.  */
  34. struct TextAttr ButtonFont    = { "diamond.font", 12, FS_NORMAL, FPF_DISKFONT };
  35. struct TextAttr Info1Font    = { "emerald.font", 17, FS_NORMAL, FPF_DISKFONT };
  36. struct TextAttr Info2Font    = { "opal.font",    9,  FS_NORMAL, FPF_DISKFONT };
  37.  
  38. struct TextFont *Button, *Info1, *Info2;
  39. struct Library    *DiskfontBase;
  40.  
  41. /*
  42.  *    Object ID's
  43.  */
  44. #define ID_QUIT                 1
  45.  
  46. /*
  47.  *    Info texts.
  48.  */
  49. UBYTE  *IText1 = ISEQ_C ISEQ_HIGHLIGHT "MultiFont";
  50. UBYTE  *IText2 = ISEQ_C "This demo shows you how you\n"
  51.          "can use different fonts inside a\n"
  52.          "single window.";
  53.  
  54. VOID StartDemo( void )
  55. {
  56.     struct Window        *window;
  57.     Object            *WO_Window, *GO_Quit;
  58.     ULONG             signal, rc;
  59.     BOOL             running = TRUE;
  60.  
  61.     /*
  62.      *    We need this one to open the fonts.
  63.      */
  64.     if ( DiskfontBase = OpenLibrary( "diskfont.library", 36 )) {
  65.         /*
  66.          *    We open the fonts ourselves since BGUI
  67.          *    opens all fonts with OpenFont() which
  68.          *    means that they have to be resident
  69.          *    in memory.
  70.          */
  71.         if ( Button = OpenDiskFont( &ButtonFont )) {
  72.             if ( Info1 = OpenDiskFont( &Info1Font )) {
  73.                 if ( Info2 = OpenDiskFont( &Info2Font )) {
  74.                     /*
  75.                      *    Create the window object.
  76.                      */
  77.                     WO_Window = WindowObject,
  78.                         WINDOW_Title,        "Multi-Font Demo",
  79.                         WINDOW_AutoAspect,    TRUE,
  80.                         WINDOW_LockHeight,    TRUE,
  81.                         WINDOW_RMBTrap,         TRUE,
  82.                         WINDOW_MasterGroup,
  83.                             VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  84.                                 StartMember,
  85.                                     VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 2 ),
  86.                                         FRM_Type,        FRTYPE_BUTTON,
  87.                                         FRM_Recessed,        TRUE,
  88.                                         StartMember,
  89.                                             InfoObject,
  90.                                                 INFO_TextFormat,    IText1,
  91.                                                 INFO_HorizOffset,    0,
  92.                                                 INFO_VertOffset,    0,
  93.                                                 INFO_FixTextWidth,    TRUE,
  94.                                                 INFO_MinLines,        1,
  95.                                                 BT_TextAttr,        &Info1Font,
  96.                                             EndObject,
  97.                                         EndMember,
  98.                                         StartMember,
  99.                                             HorizSeparator,
  100.                                         EndMember,
  101.                                         StartMember,
  102.                                             InfoObject,
  103.                                                 INFO_TextFormat,    IText2,
  104.                                                 INFO_HorizOffset,    0,
  105.                                                 INFO_VertOffset,    0,
  106.                                                 INFO_FixTextWidth,    TRUE,
  107.                                                 INFO_MinLines,        3,
  108.                                                 BT_TextAttr,        &Info2Font,
  109.                                             EndObject,
  110.                                         EndMember,
  111.                                     EndObject,
  112.                                 EndMember,
  113.                                 StartMember,
  114.                                     HGroupObject,
  115.                                         VarSpace( 50 ),
  116.                                         StartMember,
  117.                                             GO_Quit = ButtonObject,
  118.                                                 LAB_Label,    "_Quit",
  119.                                                 LAB_Underscore, '_',
  120.                                                 ButtonFrame,
  121.                                                 GA_ID,        ID_QUIT,
  122.                                                 BT_TextAttr,    &ButtonFont,
  123.                                             EndObject,
  124.                                         EndMember,
  125.                                         VarSpace( 50 ),
  126.                                     EndObject, FixMinHeight,
  127.                                 EndMember,
  128.                             EndObject,
  129.                     EndObject;
  130.  
  131.                     /*
  132.                      *    Object created OK?
  133.                      */
  134.                     if ( WO_Window ) {
  135.                         /*
  136.                          *    Assign the key to the button.
  137.                          */
  138.                         if ( GadgetKey( WO_Window, GO_Quit,  "q" )) {
  139.                             /*
  140.                              *    try to open the window.
  141.                              */
  142.                             if ( window = WindowOpen( WO_Window )) {
  143.                                 /*
  144.                                  *    Obtain it's wait mask.
  145.                                  */
  146.                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  147.                                 /*
  148.                                  *    Event loop...
  149.                                  */
  150.                                 do {
  151.                                     Wait( signal );
  152.                                     /*
  153.                                      *    Handle events.
  154.                                      */
  155.                                     while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  156.                                         /*
  157.                                          *    Evaluate return code.
  158.                                          */
  159.                                         switch ( rc ) {
  160.  
  161.                                             case    WMHI_CLOSEWINDOW:
  162.                                             case    ID_QUIT:
  163.                                                 running = FALSE;
  164.                                                 break;
  165.                                         }
  166.                                     }
  167.                                 } while ( running );
  168.                             } else
  169.                                 Tell( "Could not open the window\n" );
  170.                         } else
  171.                             Tell( "Could not assign gadget keys\n" );
  172.                         /*
  173.                          *    Disposing of the window object will
  174.                          *    also close the window if it is
  175.                          *    already opened and it will dispose of
  176.                          *    all objects attached to it.
  177.                          */
  178.                         DisposeObject( WO_Window );
  179.                     } else
  180.                         Tell( "Could not create the window object\n" );
  181.                     CloseFont( Info2 );
  182.                 } else
  183.                     Tell( "Could not open opal.font\n" );
  184.                 CloseFont( Info1 );
  185.             } else
  186.                 Tell( "Could not open emerald.font\n" );
  187.             CloseFont( Button );
  188.         } else
  189.             Tell( "Could not open diamond.font\n" );
  190.         CloseLibrary( DiskfontBase );
  191.     } else
  192.         Tell( "Could not open diskfont.library\n" );
  193. }
  194.